#ifndef OSK_DIALOG_H
#define OSK_DIALOG_H

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include <io/pad.h>

#include <ppu-types.h>

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_draw.h"

#include "types.h"

enum osk_status {
	OSK_INITIALIZED=0,
	OSK_RUNNING,
	OSK_ABORT,
	OSK_RETURN,
	OSK_END
};

struct osk_point {
	float x;
	float y;
};

struct letter_pos {
	int width;
	int height;
	int x;
	int y;
};

class OSK{
private:
	SDL_Surface *osk_surf;
	TTF_Font *osk_font;
	
	letter_pos btn;
	letter_pos del;

	osk_status status;
	osk_point pos;

	u8 mode;
	s8 sel_num;
	s8 sel_row;

	u8 cursor_pos;
	u8 show_cursor;

	char buffer[256];

	void delAtPos();
	void handleInput();

	void free_surf(SDL_Surface* surf);
	void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
	void fontWrite(int x, int y, const char* text);
	void fontPrintf(int x, int y, const char *format, ...);
	
public:
	OSK(){ status = OSK_INITIALIZED; sel_row = 0; sel_num = 0; mode = 1; };
	OSK(SDL_Surface *osk, char *usrdir);

	~OSK();

	u8 draw(int type);
	u8 handlePad();

	u8 open();

	osk_status getStatus(){ return this->status; };

	char *getBuffer();

	void setPos(osk_point npos);
};

#endif
